﻿#pragma once

#include <QObject>

//UI层
class MemsAutoTestSoftware;
class ParameterConsole;
class SetPositionModeDialog;
class SetRateModeDialog;
class SetTurnTableAndThermostatDialog;

//功能层
class MEMSDataCodec;
class MEMSDataHandler;
class MEMSDataSaver;
class ScriptRunner;
class TurnTableCodec;
class LogSaver;
//IO层
class SerialPortManager;
class FileReader;
class FileWriter;

class ConfigSaveLoader : public QObject
{
  Q_OBJECT
private:
  //UI层
  QString memsAutoTestSoftware_dataAccuracy = "memsAutoTestSoftware_dataAccuracy";
  //功能层
  QString mEMSData_dataSavingAccuracy = "mEMSData_dataSavingAccuracy";
  QString mEMSData_interval_handleData = "mEMSData_interval_handleData";
  QString mEMSData_filePaths = "mEMSData_filePaths";
  QString mEMSData_dataPackagetype = "mEMSData_dataPackagetype";
  QString mEMSData_dataCollectionProtocol = "mEMSData_dataCollectionProtocol";
  QString turnTableCodec_turnTablePositionUpperLimit = "turnTableCodec_turnTablePositionUpperLimit";
  QString turnTableCodec_turnTablePositionLowerLimit = "turnTableCodec_turnTablePositionLowerLimit";
  QString turnTableCodec_turnTableRateUpperLimit = "turnTableCodec_turnTableRateUpperLimit";
  QString turnTableCodec_turnTableRateLowerLimit = "turnTableCodec_turnTableRateLowerLimit";
  QString turnTableCodec_turnTableAccelerationUpperLimit = "turnTableCodec_turnTableAccelerationUpperLimit";
  QString turnTableCodec_turnTableAccelerationLowerLimit = "turnTableCodec_turnTableAccelerationLowerLimit";
  QString scriptRunner_interval_turnTableOperationTimeOut = "scriptRunner_interval_turnTableOperationTimeOut";
  QString logSaver_logLevel = "logSaver_logLevel";
  //IO层
  QString serialPortManager_turnTable_portName = "serialPortManager_turnTable_portName";
  QString serialPortManager_turnTable_baudRate = "serialPortManager_turnTable_baudRate";
  QString serialPortManager_turnTable_parity = "serialPortManager_turnTable_parity";
  QString serialPortManager_turnTable_dataBits = "serialPortManager_turnTable_dataBits";
  QString serialPortManager_turnTable_stopBits = "serialPortManager_turnTable_stopBits";
  QString serialPortManager_turnTable_flowControl = "serialPortManager_turnTable_flowControl";

  QString serialPortManager_mEMSData_portName = "serialPortManager_mEMSData_portName";
  QString serialPortManager_mEMSData_baudRate = "serialPortManager_mEMSData_baudRate";
  QString serialPortManager_mEMSData_parity = "serialPortManager_mEMSData_parity";
  QString serialPortManager_mEMSData_dataBits = "serialPortManager_mEMSData_dataBits";
  QString serialPortManager_mEMSData_stopBits = "serialPortManager_mEMSData_stopBits";
  QString serialPortManager_mEMSData_flowControl = "serialPortManager_mEMSData_flowControl";
private:
  QString configFilePath = "MemsAutoTestSoftware.conf";
  //UI层
  MemsAutoTestSoftware* memsAutoTestSoftware = Q_NULLPTR;
  ParameterConsole* parameterConsole= Q_NULLPTR;
  SetPositionModeDialog* setPositionModeDialog = Q_NULLPTR;
  SetRateModeDialog* setRateModeDialog = Q_NULLPTR;
  SetTurnTableAndThermostatDialog* setTurnTableAndThermostatDialog= Q_NULLPTR;
  //功能层
  MEMSDataCodec* mEMSDataCodec = Q_NULLPTR;
  MEMSDataHandler* mEMSDataHandler = Q_NULLPTR;
  MEMSDataSaver* mEMSDataSaver = Q_NULLPTR;
  ScriptRunner* scriptRunner = Q_NULLPTR;
  TurnTableCodec* turnTableCodec = Q_NULLPTR;
  LogSaver* logSaver = Q_NULLPTR;
  //IO层
  SerialPortManager* serialPortManager_turnTable = Q_NULLPTR;
  SerialPortManager* serialPortManager_mEMSData = Q_NULLPTR;
  FileReader* fileReader = Q_NULLPTR;
  FileWriter* fileWriter = Q_NULLPTR;
public:
  ConfigSaveLoader(QObject* parent = Q_NULLPTR);
  ~ConfigSaveLoader();
signals:
  void signal_loadConfigSuccessful(QString filePath);
  void signal_openConfigFileFailed(QString filePath);
  void signal_writeConfigFileSuccessful(QString filePath);
  void signal_writeConfigFileFailed(QString filePath);
public slots:
  void slot_saveConfig();
  void slot_loadConfig();

private slots:
  void slot_configFileData(QString filePath,QByteArray data);

private:
  //UI层
  void saveConfig_MemsAutoTestSoftware(QJsonObject* config);
  void loadConfig_MemsAutoTestSoftware(QJsonObject* config);
  //功能层
  void saveConfig_MEMSData(QJsonObject* config);
  void loadConfig_MEMSData(QJsonObject* config);
  void saveConfig_Script(QJsonObject* config);
  void loadConfig_Script(QJsonObject* config);
  void saveConfig_TurnTableCodec(QJsonObject* config);
  void loadConfig_TurnTableCodec(QJsonObject* config);
  void saveConfig_LogSaver(QJsonObject* config);
  void loadConfig_LogSaver(QJsonObject* config);
  //IO层
  void saveConfig_SerialPortManager(QJsonObject* config);
  void loadConfig_SerialPortManager(QJsonObject* config);

  //geter and setter
public:
  //UI层
  MemsAutoTestSoftware* getMemsAutoTestSoftware();
  void setMemsAutoTestSoftware(MemsAutoTestSoftware* memsAutoTestSoftware);
  ParameterConsole* getParameterConsole();
  void setParameterConsole(ParameterConsole* parameterConsole);
  SetPositionModeDialog* getSetPositionModeDialog();
  void setSetPositionModeDialog(SetPositionModeDialog* setPositionModeDialog);
  SetRateModeDialog* getSetRateModeDialog();
  void setSetRateModeDialog(SetRateModeDialog* setRateModeDialog);
  SetTurnTableAndThermostatDialog* getSetTurnTableAndThermostatDialog();
  void setSetTurnTableAndThermostatDialog(SetTurnTableAndThermostatDialog* setTurnTableAndThermostatDialog);
  //功能层
  MEMSDataCodec* getMEMSDataCodec();
  void setMEMSDataCodec(MEMSDataCodec* mEMSDataCodec);
  MEMSDataHandler* getMEMSDataHandler();
  void setMEMSDataHandler(MEMSDataHandler* mEMSDataHandler);
  MEMSDataSaver* setMEMSDataSaver();
  void setMEMSDataSaver(MEMSDataSaver* mEMSDataSaver);
  ScriptRunner* getScriptRunner();
  void setScriptRunner(ScriptRunner* scriptRunner);
  TurnTableCodec* getTurnTableCodec();
  void setTurnTableCodec(TurnTableCodec* turnTableCodec);
  LogSaver* getLogSaver();
  void setLogSaver(LogSaver* logSaver);
  //IO层
  FileReader* getFileReader();
  void setFileReader(FileReader* fileReader);
  FileWriter* getFileWriter();
  void setFileWriter(FileWriter* fileWriter);
  SerialPortManager* getSerialPortManager_turnTable();
  void setSerialPortManager_turnTable(SerialPortManager* serialPortManager_turnTable);
  SerialPortManager* getSerialPortManager_mEMSData();
  void setSerialPortManager_mEMSData(SerialPortManager* serialPortManager_mEMSData);
};
